#pragma once

#include <grpc++/grpc++.h>
#include "../../proto/rpc.grpc.pb.h"
#include "../action.hpp"
#include "rsp_watch.hpp"
#include "response.hpp"


using grpc::ClientAsyncReaderWriter;
using etcdserverpb::WatchRequest;
using etcdserverpb::WatchResponse;


namespace etcdv3 {
class AsyncWatchAction : public Action {
public:
    AsyncWatchAction(const ActionParameters& param);
    AsyncWatchResponse ParseResponse();
    void waitForResponse();
    void waitForResponse(std::function<void(const etcd::Response&)> callback);
    void CancelWatch();
private:
    WatchResponse reply;
    std::unique_ptr<ClientAsyncReaderWriter<WatchRequest, WatchResponse>> stream;
    bool isCancelled;
};

}
